package com.zhengshang.api.service.impl;

import java.util.List;

import com.zhengshang.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhengshang.api.mapper.AppBillRecordMapper;
import com.zhengshang.api.domain.AppBillRecord;
import com.zhengshang.api.service.IAppBillRecordService;

/**
 * 话费充值记录Service业务层处理
 *
 * @author zhengshang
 * @date 2021-06-07
 */
@Service
public class AppBillRecordServiceImpl implements IAppBillRecordService {
    @Autowired
    private AppBillRecordMapper appBillRecordMapper;

    /**
     * 查询话费充值记录
     *
     * @param recordId 话费充值记录ID
     * @return 话费充值记录
     */
    @Override
    public AppBillRecord selectAppBillRecordById(Long recordId) {
        return appBillRecordMapper.selectAppBillRecordById(recordId);
    }

    @Override
    public AppBillRecord selectAppBillRecordByPayId(Long payId) {
        return appBillRecordMapper.selectAppBillRecordByPayId(payId);
    }

    @Override
    public AppBillRecord selectAppBillRecordByOrderNum(String orderNum) {
        return appBillRecordMapper.selectAppBillRecordByOrderNum(orderNum);
    }

    /**
     * 查询话费充值记录列表
     *
     * @param appBillRecord 话费充值记录
     * @return 话费充值记录
     */
    @Override
    public List<AppBillRecord> selectAppBillRecordList(AppBillRecord appBillRecord) {
        return appBillRecordMapper.selectAppBillRecordList(appBillRecord);
    }

    @Override
    public List<AppBillRecord> queryAppBillRecordList(AppBillRecord appBillRecord) {
        return appBillRecordMapper.queryAppBillRecordList(appBillRecord);
    }

    /**
     * 新增话费充值记录
     *
     * @param appBillRecord 话费充值记录
     * @return 结果
     */
    @Override
    public int insertAppBillRecord(AppBillRecord appBillRecord) {
        appBillRecord.setCreateTime(DateUtils.getNowDate());
        return appBillRecordMapper.insertAppBillRecord(appBillRecord);
    }

    /**
     * 修改话费充值记录
     *
     * @param appBillRecord 话费充值记录
     * @return 结果
     */
    @Override
    public int updateAppBillRecord(AppBillRecord appBillRecord) {
        if (ObjectUtils.isNotEmpty(appBillRecord)) {
            appBillRecord.setUpdateTime(DateUtils.getNowDate());
            return appBillRecordMapper.updateAppBillRecord(appBillRecord);
        }
        return 0;
    }

    /**
     * 批量删除话费充值记录
     *
     * @param recordIds 需要删除的话费充值记录ID
     * @return 结果
     */
    @Override
    public int deleteAppBillRecordByIds(Long[] recordIds) {
        return appBillRecordMapper.deleteAppBillRecordByIds(recordIds);
    }

    /**
     * 删除话费充值记录信息
     *
     * @param recordId 话费充值记录ID
     * @return 结果
     */
    @Override
    public int deleteAppBillRecordById(Long recordId) {
        return appBillRecordMapper.deleteAppBillRecordById(recordId);
    }

    @Override
    public int countCouponOrder(Long userId) {
        AppBillRecord appBillRecord = new AppBillRecord();
        appBillRecord.setRemark("100");
        appBillRecord.setUserId(userId);
        List<AppBillRecord> list = queryAppBillRecordList(appBillRecord);
        if (ObjectUtils.isNotEmpty(list)) {
            return list.size();
        } else {
            return 0;
        }
    }
}
